#include "Parser.h"




Parser::Parser(Buffer* b){
	this->automat = new AutomatComp(b);
	this->token = automat->nextToken();
	//Knoten StmtList
    this->statementlist();
	
}


void Parser::statementlist(){
     if (token->getType() == IDENTIFIER || PRINT){
		//Knoten Stmt
		this->statement();
		//Knoten StmtList2 usw.
		this->statementlist2();
	 }
	 	 else ; //error

}

void Parser::statementlist2(){
	if (token->getType() == SEMICOLON){
		token = automat->nextToken();
		this->statement();
		this->statementlist2();
	}else if (token->getType() == EOF){
	}
	else {
		//error
	}
}


void Parser::statement(){
	if (token->getType() == IDENTIFIER){
		token = automat->nextToken();
		if (token->getType() != ASSIGN)	{
			//error; exit(0);
		}else {
			token = automat->nextToken();
			this->exp();
		}
	}else if (token->getType() == PRINT){
		token = automat->nextToken();
		if (token->getType() != KLAMMERAUF)	{
			//error; exit(0);
		}else {
	 		token = automat->nextToken();
			this->exp();
		}
		if (token->getType() != KLAMMERZU) {
			//error; exit(0);
		}else {
	 		token = automat->nextToken();
		}
	}else {
		//error; 
	}
}


void Parser::exp(){
	if (token->getType() == KLAMMERAUF || IDENTIFIER || INTEGER || REAL || SIGNMINUS || SUM || PROD){
		this->exp2();
		this->op_exp();
	}else {
		//error
	}
}

void Parser::exp2(){
	if (token->getType() == KLAMMERAUF || IDENTIFIER){
		token = automat->nextToken();
		this->exp3();
	}else if (token->getType() == INTEGER || REAL){
		//fertig
	}else if (token->getType() == SIGNMINUS){
		token = automat->nextToken();
		this->exp2();
	}else if (token->getType() == SUM){
		token = automat->nextToken();
		if (token->getType() != KLAMMERAUF){
			//error
		}else{
			token = automat->nextToken();
			this->explist();
			if (token->getType() != KLAMMERZU){
				//error
			}else {
				token = automat->nextToken();
			}
		}
	}else if (token->getType() == PROD){
		token = automat->nextToken();
		if (token->getType() != KLAMMERAUF){
			//error
		}else{
			token = automat->nextToken();
			this->explist();
			if (token->getType() != KLAMMERZU){
				//error
			}else {
				token = automat->nextToken();
			}
		}
	}else {
		//error
	}
}

void Parser::exp3(){
	if (token->getType() != KLAMMERAUF || IDENTIFIER){
		//error
	}else {
		token = automat->nextToken();
		if (token->getType() == IDENTIFIER){
			//fertig
		}else {
			this->exp();
			token = automat->nextToken();
			if (token->getType() != KLAMMERZU){
				//error
			}else {
				token = automat->nextToken();
			}
		}
	}
}

void Parser::op_exp(){
	if (token->getType() == SIGNPLUS || SIGNMINUS || STAR || SIGNDIV || DURCH || MODULO){
		this->op();
		this->exp();
	}else if (token->getType() == KLAMMERAUF || IDENTIFIER){
		this->exp3();
	}else if (token->getType() == EOF){
	}else {
		//error
	}
}

void Parser::explist(){
	if (token->getType() == KLAMMERAUF || IDENTIFIER || INTEGER || REAL || SIGNMINUS || SUM || PROD){
		this->exp();
		this->explist2();
	}else {
		//error
	}
}

void Parser::explist2(){
	if (token->getType() == SEMICOLON){
		token = automat->nextToken();
		this->exp();
		this->explist2();
	}else if (token->getType() == EOF){
	}else {
		//error
	}
}

void Parser::op(){
	if (token->getType() == SIGNPLUS || SIGNMINUS || STAR || SIGNDIV || DURCH || MODULO){
		token = automat->nextToken();

		//fertig
	}
}